package vue;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import controleur.ControleAddKnowledge;
import controleur.ControleReturn;

import modele.CKModel;

public class PanelAddKnowledge extends JPanel {

	
	static final long serialVersionUID = 12345;
	
	CKModel<String,String> _modele;
	VueEditeurCK _vue;
	
	private JLabel lblK;

	private JScrollPane scp;
	private JTextArea txtK;
	
	private JLabel lblC;
	private ButtonGroup choix;
	
	private JRadioButton rbK;
	private JComboBox cmbC;
	
	private JRadioButton rbNk;
	
	private JButton btnAddK;
	private JButton btnR;
	
	
	public PanelAddKnowledge(CKModel<String,String> modele, VueEditeurCK vue){
		
		_modele = modele;
		_vue = vue;
		
		
		this.setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		this.setPreferredSize(new Dimension(_vue.getFrameWidth(), _vue.getFrameHeight()/3));
		gbc.gridx = GridBagConstraints.RELATIVE;
        gbc.gridy = GridBagConstraints.RELATIVE;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.ipadx = 0;
        gbc.ipady = 0;
        Insets i = new Insets(5, 5, 5, 5);
		gbc.insets = i;
        gbc.anchor = GridBagConstraints.CENTER;
		
		
		 
		lblK = new JLabel("Entrez un Knowledge");
		lblK.setPreferredSize(new Dimension(200,30));
		gbc.gridx = 0;
		gbc.gridy = 0;
		this.add(lblK, gbc);
		
		txtK = new JTextArea();
		txtK.setLineWrap(true);
		scp = new JScrollPane(txtK, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
		        JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		gbc.gridx = 1;
		gbc.gridy = 0;
		gbc.weighty = 2;
		gbc.weightx = 2;
		this.add(scp, gbc);
		
		choix = new ButtonGroup();
		
		rbK = new JRadioButton("Oui", true);
		choix.add(rbK);
		gbc.gridx = 0;
		gbc.gridy = 2;
		this.add(rbK, gbc);
		
		cmbC = new JComboBox();
		cmbC.setPreferredSize(new Dimension(200,30));
		this.LoadConcept();
		gbc.gridx = 1;
		gbc.gridy = 2;
		this.add(cmbC, gbc);
		
		rbNk = new JRadioButton("Non", false);
		choix.add(rbNk);
		gbc.gridx = 0;
		gbc.gridy = 3;
		gbc.weighty = 0.0;
		gbc.weightx = 0.0;
		this.add(rbNk, gbc);
		
		btnAddK = new JButton("Valider");
		btnAddK.setPreferredSize(new Dimension(100,30));
		btnAddK.addActionListener(new ControleAddKnowledge(_modele, _vue));
		gbc.gridx = 2;
		gbc.gridy = 3;
		this.add(btnAddK, gbc);
		
		btnR = new JButton("Retour");
		btnR.setPreferredSize(new Dimension(100,30));
		btnR.addActionListener(new ControleReturn(_modele, _vue));
		gbc.gridx = 2;
		gbc.gridy = 4;
		this.add(btnR, gbc);
		
		lblC = new JLabel("Cette connaissance à un lien avec un des concept suivants : ");
		gbc.gridx = 0;
		gbc.gridy = 1;
		gbc.gridwidth = GridBagConstraints.RELATIVE;
        gbc.gridheight = 1;
        gbc.weightx = 0.0;
        gbc.weighty = 0.0;
		this.add(lblC, gbc);
	}
	
	public void LoadConcept(){
		cmbC.removeAllItems();
		for (int i=0; i<_modele.getCSize(); i++){
			this.cmbC.addItem(_modele.findConceptFromId(i));
		}
	}
	
	public String getTextK(){
		return this.txtK.getText();
	}
	
	public JRadioButton getRdbK(){
		return this.rbK;
	}
	
	public JRadioButton getRdbNk(){
		return this.rbNk;
	}
	
	public JComboBox getCmbC(){
		return this.cmbC;
	}


	/**
	 * @return the btnR
	 */
	public JButton getBtnR() {
		return btnR;
	}
	
	
}
